﻿using UnityEngine;
using System.Collections;

public class ArmoryScrollObjects : MonoBehaviour
{

    public float fBarFirstPosY;

    float fMaxScrolledY;  //최대로 스크롤내렷을때 parent Y 위치

    int iListCount;
    int iNumOfMaxLists; //한번에 창에보이는 최대 개수

    float fListSize;  //리스트 한개사이즈

    float fMinBarPos;

    float fBarDefaultYPos;
    float fBarYPosPlus;

    public bool bSmallThanMinBarSize;

    // Use this for initialization
    void Start()
    {
        fListSize = 6f;

        iListCount = GameObject.Find("LabelLists").transform.childCount;
        iNumOfMaxLists = 12;

        fBarDefaultYPos = 8.87f;
        fBarYPosPlus = 2.07f;

        fMaxScrolledY = ((iListCount - iNumOfMaxLists) * fListSize);
    }

    // Update is called once per frame
    void Update()
    {
        //if (!bSmallThanMinBarSize)
        //{
        //    float fScrollYRate = (GameObject.Find("ScrollBar").transform.localPosition.y - fBarFirstPosY);

        //    transform.localPosition = new Vector3(transform.localPosition.x, fScrollYRate / fMaxScrolledY);
        //}
        //else
        {
            if (GameObject.Find("ScrollBar"))
            {
                float fScrollYRate = (GameObject.Find("ScrollBar").transform.localPosition.y - fBarFirstPosY);

                transform.localPosition = new Vector3(transform.localPosition.x, fScrollYRate * fMaxScrolledY / (fBarFirstPosY - (fBarDefaultYPos - (((float)iListCount - (float)iNumOfMaxLists) * fBarYPosPlus))) * -1);
            }
            else
            {
                transform.localPosition = Vector3.zero;
            }
        }
    }
}
